<?php

# database connection
include '../lib5/pdoExt.php';
include 'dbConn.php';

# objlib library code
include '../lib5/Util.php';
include '../lib5/Object.php';
include '../lib5/JoinerRelation.php';
include '../lib5/SortedJoinerRelation.php';
include '../lib5/KeyRelation.php';
include '../lib5/SortedKeyRelation.php';
include '../lib5/Query.php';
include '../lib5/Node.php';


# englopya library code
foreach (glob ('../Classes/*.php') as $componentFile) {
        include_once ($componentFile);
}

foreach (glob ('../Classes/Component/*.php') as $componentFile) {
        include_once ($componentFile);
}

# englopya Relations
foreach (glob ('../Classes/Relations/*.php') as $relationFile) {
        include_once ($relationFile);
}

# reset database
$dbh->exec ('drop table Page');
$dbh->exec ('drop table Article');
$dbh->exec ('drop table Style');
$dbh->exec ('drop table Template');
$dbh->exec ('drop table Component');
$dbh->exec ('drop table URL');
$dbh->exec ('drop table Nav');
$dbh->exec ('drop table NavHasNav');

$style = new Style (false, 'Style1');
$style->header = ('<html><body>');
$style->footer = ('</body></html>');
$style->save ();

$templ = new Template (false, 'Template1');
$templ->content = '<?php /*TMPL_POS*/ ?>';
$templ->save ();

$page = new Page (false, false, array (
	'title'      => 'Page1',
	'URL'        => 'FirstPage', 
	'styleId'    => $style->id(),
	'templateId' => $templ->id()
));
$page->save ();

$article = new Article (false, false, array (
	'title'      => 'Article1',
	'URL'        => 'FirstArticle', 
	'styleId'    => $style->id(), 
	'templateId' => $templ->id(), 
	'content'    => 'This is a test article: <?php echo $this->title ?><br> In a test page: <?php echo $this->page->title ?>'
));
$article->save ();

PageHasComponent::relate ($page, $article);

$page->render ();

/*or
$article->page = $page;
$article->render();
*/

?>